﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace WenXia
{
    class AnimatedSprite : DrawableGameComponent
    {
        protected string asset;
        protected Texture2D tex;
        protected Rectangle currentRect;
        protected Rectangle destRect;
        protected SpriteBatch spriteBatch;
        public AnimatedSprite(Game game, string asset)
            : base(game)
        {
            this.asset = asset;
            this.DrawOrder = 8;
            this.spriteBatch = new SpriteBatch(Game.GraphicsDevice);
        }
        protected override void LoadContent()
        {
            tex=Game.Content.Load<Texture2D>(asset);
            base.LoadContent();
        }
        public void SetPosition(int x, int y)
        {
            currentRect.X = x;
            currentRect.Y = y;
        }
        public void SetRegion(int x, int y, int width, int height)
        {
            currentRect.X = x;
            currentRect.Y = y;
            currentRect.Width = width;
            currentRect.Height = height;
        }
        public void Scale(float factor)
        {
            currentRect.Width = (int)(currentRect.Width * factor);
            currentRect.Height = (int)(currentRect.Height * factor);
        }
        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(tex, currentRect, Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
